package com.kedi.usercenter.service.impl;

import com.kedi.usercenter.enums.ResultEnum;
import com.kedi.usercenter.exception.CommonException;
import com.kedi.usercenter.read.mapper.ChildrensetMapper;
import com.kedi.usercenter.service.ChildrensetService;
import com.kedi.usercenter.write.mapper.WriteChildrensetMapper;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

@Service
public class ChildrensetServiceImpl implements ChildrensetService {
    private static Logger logger = LoggerFactory.getLogger(ChildrensetServiceImpl.class);
    @Autowired
    WriteChildrensetMapper mapper;

    @Autowired
    ChildrensetMapper mapper1;

    @Transactional
    @Override
    public Integer createaffectionphone(Map map) {


            return mapper.createaffectionphone(map);


    }

    @Override
    public Integer createmydrug(Map map) {

        return mapper.createmydrug(map);
    }

    @Override
    public List  findChildrenset(Integer p_user_id) {
        List<Map<String, Object>> list1 = mapper1.findaffectionphone(p_user_id);
        List<Map<String, Object>> list2= mapper1.findmydrug(p_user_id);
        ArrayList<List<Map<String, Object>>> list = new ArrayList<>();
        list.add(list1);
        list.add(list2);
        return  list;

    }

    @Override
    public Integer deleteaffectionphone(Map map) {

         Integer integer = mapper.deleteaffectionphone(map);
        if(integer<0){
            logger.info("删除亲情号码失败");
            throw new CommonException(ResultEnum.DELET_ERROR);
        }else{
            return integer;
        }
    }
}
